<template>
  <div class="rightBodyContent">
    <div class="rightBodyContent-in">
      <div class="hearder-search">
        <div class="toplineBox mb-10">
          <div class="toplineBox-left">
            <el-input v-model="editForm.title" placeholder="填写标题" size="small" class="w-140 mr-10"></el-input>
            <el-button type="primary" size="small" @click="searchFn"><i class="el-icon-search"></i>搜索</el-button>
            <el-button size="small" @click="refreshFn"><i class="el-icon-refresh"></i>刷新</el-button>
            <el-button type="primary" size="small" @click="recruitId=0,detailVisible=true" plain>新增招生简章</el-button>
          </div>
          <p class="numberline toplineBox-right">总{{ page.total }}条</p>
        </div>
      </div>
      <div class="table-body">
        <div class="table-body-box">
          <el-table
              ref="multipleTable"
              :data="arryList"
              :stripe="tableStyle.tableStripe"
              :border="tableStyle.tableBorder"
              tooltip-effect="dark"
              style="width: 100%"
              header-cell-class-name="table-text-c"
              cell-class-name="table-text-c">
            <el-table-column
                prop="id"
                label="ID"
                width="70">
            </el-table-column>
            <el-table-column
                prop="title"
                label="标题">
            </el-table-column>
            <!--            @return apply_number:申请数量-->
            <!--            * @return entertain_number:招待人数-->
            <!--            * @return adopt_number:通过人数-->
            <!--            * @return reject_number:驳回人数-->
            <el-table-column
                prop="number"
                label="拟招人数">
            </el-table-column>
            <el-table-column
                prop="apply_number"
                label="申请人数">
            </el-table-column>
            <el-table-column
                label="通过数/驳回数">
              <template slot-scope="scope">
                {{ `${scope.row.adopt_number}/${scope.row.reject_number}` }}
              </template>
            </el-table-column>
            <el-table-column
                prop="end_time"
                label="截止时间">
            </el-table-column>
            <el-table-column
                label="发布人">
              <template slot-scope="scope">
                {{ scope.row.admin ? scope.row.admin.realname : '--' }}
              </template>
            </el-table-column>
            <!--顺序排序-->
            <el-table-column
                label="操作"
                width="320">
              <template slot-scope="scope">
                <el-button size="small" @click="qrcodeOption=scope.row,qrcodeVisible=true" plain type="warning">
                  二维码
                </el-button>
                <el-button size="small" @click="recruitId=scope.row.id,detailVisible=true" plain>招生编辑</el-button>
                <el-button type="primary" size="small" @click="recruitId=scope.row.id,listVisible=true" plain>招生申请明细
                </el-button>
                <!--              发布者总管理可删除-->
                <!--              <el-button type="danger" size="small" @click="handleDetel(scope.$index)" plain v-if="activeName=='2'">-->
                <!--                删除-->
                <!--              </el-button>-->
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <!--工具条 分页-->
      <el-col :span="24" class="toolbar">
        <el-pagination
            background
            layout="prev, pager, next"
            :total="page.total"
            :page-size="page.pagesize"
            @current-change="handleSizeChange">
        </el-pagination>
      </el-col>
      <!--    <workDetail :visible.sync="workeDetailVisible" :workId="workId" acticveWorke="3"></workDetail>-->
      <!--    <addWorke :visible.sync="detailVisible"></addWorke>-->
      <!--      二维码-->
      <recruit_qrcode :visible.sync="qrcodeVisible" :qrcodeOption="qrcodeOption"></recruit_qrcode>
      <!--      招生详情-->
      <recruit_list :visible.sync="listVisible" :recruitId="recruitId"></recruit_list>
      <!--      添加编辑-->
      <add_recruit :visible.sync="detailVisible" :recruitId="recruitId"></add_recruit>
    </div>
  </div>
</template>

<script>
import {pagination, tableoption} from '@/utils/util.js'
import recruit_qrcode from "./components/recruit_qrcode";
import recruit_list from "./components/recruit_list";
import add_recruit from "./components/add_recruit";
import api from '@/utils/api.js'
import {mapGetters} from "vuex";
import {recuitIndex} from '@/api/admin/recuit'

export default {
  props: ['tabchildValue', 'tabValue'],
  components: {
    recruit_qrcode,
    recruit_list,
    add_recruit
  },
  computed: {
    ...mapGetters(['userInfo']),
  },
  watch: {
    activeName() {
      this.page.pageindex = 1
      this.InitFn()
    }
  },
  data() {
    return {
      detailVisible: false,
      listVisible: false,
      qrcodeVisible: false,
      recruitId: 0,
      arryList: [], // 页面数据列表
      qrcodeOption: null,
      // 设置table样式
      tableStyle: tableoption,
      // 设置table页面分页所需
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      editBox: null,
      clickStatus: null,
      workId: 0,
      editForm: {
        title: '',
        p: '',
      },
      userInfomation: null,
    }
  },
  created() {
    this.InitFn()
  },
  methods: {
    // 初始化
    async InitFn() {
      let option = this.getJson(this.editForm)
      option.p = this.page.pageindex
      // let data = await this.$post(this.api.task.archives.index, this.editForm);
      option.style = 2 // 我的发布1  总揽 2
      recuitIndex(option).then(res => {
        for (let item of res.list.data) {
          item.create_time = item.create_time.split(' ')[0]
        }
        this.arryList = res.list.data
        this.page.total = res.list.total
      })
    },
    getJson(item){
      return JSON.parse(JSON.stringify(item))
    },
    searchFn() {
      this.page.pageindex = 1
      this.InitFn()
    }
    ,
// 编辑 执行情况
    handleEdit(id) {
      this.taskId = id
      this.dialogDrawerVisible = true
    }
    ,
// 任务详情 数据获取
    taskDetail(id) {
      this.taskId = id
      this.detailVisible = true
    },
// 刷新页面
    refreshFn() {
      this.page.pageindex = 1
      this.editForm.title = ''
      this.InitFn()
    },
// 设置默认选中
    checked(option) {
      if (option === 'first' && JSON.stringify(this.applyBookBox) !== '{}') {
        this.applyBookBox = {}
        this.$refs.table.clearSelection()
      }
      for (let i = 0; i < this.userList.length; i++) {
        if (this.applyBookBox[this.userList[i].id]) {
          this.$refs.table.toggleRowSelection(this.userList[i], true)
        }
      }
    }
    ,
// 分页
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    }
    ,
// 刷新详情信息
    getUser() {
      this.taskDetail(this.editBox, 'refreshFn')
    }
    ,
// 弹窗
    checkTask() {

    }
    ,
    handleDetel(index) {
      this.$confirm('确认永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.detelRespon(index)
      }).catch(() => {
      })
    }
    ,
    detelRespon(index) {
      this.$post(api.task_delete, {id: this.arryList[index].id}).then((response) => {
        if (response.code === 0) {
          this.arryList.splice(index, 1)
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        } else {
        }
      }).catch((err) => {
        console.log(err)
      })
    }
  },
  mounted() {
  }
}
</script>

<style lang="scss" scoped>
.evaluateBox {
  background: #eee;
  margin-top: 5px;
  border-radius: 4px;
  padding: 5px;
}

.lookLsit {
  cursor: pointer;
}

.lookLsit:hover {
  text-decoration: underline;
}

#tablebox {
  display: flex;
  flex-direction: column;
}

.el-table {
  color: #000;
}

.right-box .container .main .content-container .input-val-box .input-top {
  width: 250px;
}
</style>
